<template>
  <div class="GCompanyCheck">
    <filterPanel filterName="GCompanyCheckFilter" filterTitle="" :filterList="filterData"
                 @filterChange="filterChange" title="企业审核查询"></filterPanel>
    <tablePanel tableName="GCompanyCheckTable" title="企业审核列表" :tableLoading="loading" tableTitle=""
                :tableList="tableList" :tableData="tableData" :total="total" :currentPage="form.page_start"
                :pageSize="form.page_size" @sizeChange="sizeChange" @pageChange="pageChange" @tableClick="tableClick">
      <zy-button @click="exportExcel">导出列表</zy-button>
    </tablePanel>
  </div>
</template>

<script>
	import {mapGetters} from "vuex";

	export default {
		name: "GCompanyCheck",
		props: {},
		data() {
			return {
				currentPath: '/company_check',
				filterData: [
					{
						title: '企业编号',
						name: 'company_sn',
						type: 'input',
						value: '',
						maxlength: '20',
						isShow: true,
						isSelected: true
					},
					{
						title: '企业名称',
						name: 'company_name',
						type: 'input',
						value: '',
						maxlength: '20',
						isShow: true,
						isSelected: true
					},
					{
						title: '企业类型',
						name: 'type',
						type: 'select',
						optionList: [
							{label: '全部', value: ''},
							{label: '物流', value: 0},
							{label: '快递', value: 1},
							{label: '分拣中心', value: 2},
						],
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '统一社会信用代码',
						name: 'organization_code',
						type: 'input',
						value: '',
						maxlength: '20',
						isShow: true,
						isSelected: true
					},
					{
						title: '法人姓名',
						name: 'legal_person',
						type: 'input',
						value: '',
						maxlength: '20',
						isShow: true,
						isSelected: true
					},
					{
						title: '法人联系方式',
						name: 'legal_phone',
						type: 'input',
						value: '',
						maxlength: '11',
						isShow: true,
						isSelected: true
					},
					{
						title: '法人身份证',
						name: 'legal_card_no',
						type: 'input',
						value: '',
						maxlength: '18',
						isShow: true,
						isSelected: true
					},
					{
						title: '审核状态',
						name: 'apply_status',
						type: 'select',
						optionList: [
							{label: '全部', value: ''},
							{label: '待审核', value: 0},
							{label: '审核通过', value: 1},
							{label: '审核不通过', value: 2},
						],
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '监管辖区',
						name: 'regulated_id',
						type: 'select',
						optionList: [],
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '注册时间',
						name: 'registration_date',
						type: 'date',
						value: [],
						isShow: true,
						isSelected: true
					},
				],
				form: {
					company_sn: '',
					company_name: '',
					type: '',
					organization_code: '',
					legal_person: '',
					legal_phone: '',
					legal_card_no: '',
					status: '',
					regulated_id: '',
					registration_date: [],
					page_start: 1,
					page_size: 10
				},
				loading: false,
				tableList: [
					{
						title: '企业编号',
						width: 200,
						name: 'company_sn',
						isShow: true,
						isSelected: true
					},
					{
						title: '企业名称',
						width: 200,
						name: 'company_name',
						isShow: true,
						isSelected: true
					},
					{
						title: '企业类型',
						width: 100,
						name: 'type_desc',
						isShow: true,
						isSelected: true
					},
					{
						title: '统一社会信用代码',
						width: 200,
						name: 'organization_code',
						isShow: true,
						isSelected: true
					},
					{
						title: '法人姓名',
						width: 120,
						name: 'legal_person',
						isShow: true,
						isSelected: true
					},
					{
						title: '法人联系方式',
						width: 160,
						name: 'legal_phone',
						isShow: true,
						isSelected: true
					},
					{
						title: '法人身份证号',
						width: 200,
						name: 'legal_card_no',
						isShow: true,
						isSelected: true
					},
					{
						title: '审核状态',
						width: 120,
						name: 'apply_status_name',
						isShow: true,
						isSelected: true
					},
					{
						title: '创建时间',
						width: 180,
						name: 'created_time',
						isShow: true,
						isSelected: true
					},
					{
						title: '监管辖区',
						width: 200,
						name: 'regulated_name',
						isShow: true,
						isSelected: true
					},
					{
						title: '操作',
						width: 200,
						name: 'handler',
						fixed: 'right',
						btns: [
							{
								type: 'detail',
								name: '详情'
							},
							{
								type: 'check',
								name: '审核',
								btnType: 'warring'
							},
						],
						isSelected: true
					}
				],
				tableData: [],
				total: 0,
				download_url: ''
			};
		},
		computed: {
			postData() {
				let data = {
					company_name: this.form.company_name,
					type: this.form.type,
					organization_code: this.form.organization_code,
					legal_person: this.form.legal_person,
					legal_phone: this.form.legal_phone,
					legal_card_no: this.form.legal_card_no,
					apply_status: this.form.apply_status,
					regulated_id: this.form.regulated_id,
					company_type: 1,
					pagination: {
						page_start: this.form.page_start,
						page_size: this.form.page_size
					}
				};
				if (this.form.registration_date && this.form.registration_date.length > 0) {
					data.start_created_time = this.form.registration_date[0] / 1000;
					data.end_created_time = this.form.registration_date[1] / 1000;
				}
				return data;
			},
			...mapGetters(['authority']),
			isLook() {
				return this.authority[this.currentPath] && this.authority[this.currentPath].q;
			},
			isCheck() {
				return this.authority[this.currentPath] && this.authority[this.currentPath].c;
			},
		},
		watch: {},
		components: {},
		methods: {
			//导出
			exportExcel() {
				this.$import_excal(this.download_url || "");
			},
			sizeChange(val) {
				this.form.page_size = val;
				this.getData()
			},
			pageChange(val) {
				this.form.page_start = val;
				this.getData()
			},
			filterChange(data) {
				this.form = {...this.form, ...data};
				this.getData();
			},
			getData() {
				this.loading = true;
				this.$axios.post(this.$api.companyApplyList, {...this.postData}).then(res => {
					let {code, msg, data} = res;
					this.loading = false;
					if (code == 200) {
						let arr = ['物流', '快递', '分拣中心']
						this.tableData = data.list.filter(item => {
							item.type_desc = arr[item.type];
							item.detail = this.isLook;
							item.check = this.isCheck && item.apply_status == 0;
							return item;
						});
						this.total = data.pagination.total_count || 0;
						this.download_url = data.download_url || ''
					} else {
						this.total = 0;
						this.tableData = [];
					}
				}).catch(ret => {
					this.$message.error(ret.msg || '服务繁忙，请稍后再试');
				});
			},
			getRegulatedData() {
				this.$axios.post(this.$api.g_regulatedList, {
					pagination: {
						page_start: 1,
						page_size: 9999
					}
				}).then(res => {
					let {code, msg, data} = res;
					if (code == 200) {
						this.setFilterData({
							regulated_id: data.list.filter(item => {
								item.value = item.regulated_id;
								item.label = item.regulated_name
								return item;
							}),
						}, ['regulated_id']);
					} else {
						this.$message.error(msg);
					}
				}).catch(ret => {
					this.$message.error(ret.msg || '服务繁忙，请稍后再试');
				});
			},
			setFilterData(val, nameList) {
				for (let item of this.filterData) {
					if (nameList.indexOf(item.name) !== -1) {
						item.optionList = val[item.name]
					}
				}
			},
			tableClick(data, type) {
				let {apply_id} = data
				this.toDetail(apply_id, type);
			},
			// 去详情
			toDetail(apply_id, type) {
				this.$toRoutePath({
					path: "/company_check/company_check_detail",
					edit: true,
					query: {type, apply_id}
				});
			},
		},
		mounted() {
			this.getData();
			this.getRegulatedData();
		},
		created() {
		},
	}
</script>

<style scoped lang="less" src="@/style/government/company/companyCheckList/index.less">

</style>
